require 'statistic/html_fields_counter'
require "rexml/document"

module Statistic
  
  class BloggerFieldsCounter < HTMLFieldsCounter
    
    public
    
    def initialize( crawl_table, conditions = "status = 200" )
      super crawl_table, conditions
    end
    
    
    def analyse_html(xml_tree)
      #informazioni sul profilo con dettaglio a livello di link
      matchs = REXML::XPath.match xml_tree, "/html/body/div[@id='body']/div/div[@id='main-wrap']/div[@id='main']/div[@id='m2']/div[@id='m3']/ul/li/span"
      matchs.each {|e| @fields_stat[e.attribute(:class).value] += 1}
      # informazioni sul profilo con dettaglio a livello di titolo
      matchs = REXML::XPath.match xml_tree, "/html/body/div[@id='body']/div/div[@id='main-wrap']/div[@id='main']/div[@id='m2']/div[@id='m3']/ul/li/strong"
      matchs.each {|e| @fields_stat[e.text.downcase.chomp ':'] += 1}
      #cerchiamo l'email
      matchs = REXML::XPath.match xml_tree, "/html/body/div[@id='body']/div/div[@id='sidebar']/div/div/div/ul/li/script/comment()"
      matchs.each {|e| @fields_stat["email"] += 1}
      #informazioni del blog conttatta
      matchs = REXML::XPath.match xml_tree, "/html/body/div[@id='body']/div/div[@id='sidebar']/div/div/div/table/tr/th"
      matchs.each {|e| @fields_stat[e.text.downcase] += 1}
      # interessi personali, film ecc.. a livello di titolo
      matchs = REXML::XPath.match xml_tree, "/html/body/div[@id='body']/div/div[@id='main-wrap']/div[@id='main']/div[@id='m2']/div[@id='m3']/h2"
      matchs.each {|e| @fields_stat[e.text.downcase] += 1}
      
      # interessi personali, film ecc.. a livello di titolo di link
      matchs = REXML::XPath.match xml_tree, "count(/html/body/div[@id='body']/div/div[@id='main-wrap']/div[@id='main']/div[@id='m2']/div[@id='m3']/ul/li/a[contains(@href,'t=b')]) > 0"
      @fields_stat["favorite book link"] += 1 if matchs[0]
      
      matchs = REXML::XPath.match xml_tree, "count(/html/body/div[@id='body']/div/div[@id='main-wrap']/div[@id='main']/div[@id='m2']/div[@id='m3']/ul/li/a[contains(@href,'t=m')]) > 0"
      @fields_stat["favorite movie link"] += 1 if matchs[0]
      
      matchs = REXML::XPath.match xml_tree, "count(/html/body/div[@id='body']/div/div[@id='main-wrap']/div[@id='main']/div[@id='m2']/div[@id='m3']/ul/li/a[contains(@href,'t=s')]) > 0"
      @fields_stat["favorite music link"] += 1 if matchs[0]
      
      matchs = REXML::XPath.match xml_tree, "count(/html/body/div[@id='body']/div/div[@id='main-wrap']/div[@id='main']/div[@id='m2']/div[@id='m3']/ul/li/a[contains(@href,'t=i')]) > 0"
      @fields_stat["favorite interests link"] += 1 if matchs[0]
      
      
    end
  end
  
end # module Statistic